////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#ifndef FM3_USART_H_
#define FM3_USART_H_

/*
 *  Register Bit Definition
 */
#define SMR_SOE          0x01U
#define SMR_BDS          0x04U
#define SMR_SBL          0x08U
#define SMR_WUCR         0x10U
#define SMR_MD_UART      0x00U
#define SMR_MD_UART_MP   0x20U
#define SMR_MD_SIO       0x40U
#define SMR_MD_LIN       0x60U
#define SMR_MD_I2C       0x80U

#define SCR_TXE          0x01U
#define SCR_RXE          0x02U
#define SCR_TBIE         0x04U
#define SCR_TIE          0x08U
#define SCR_RIE          0x10U
#define SCR_UPGL         0x80U

#define SSR_TBI          0x01U
#define SSR_TDRE         0x02U
#define SSR_RDRF         0x04U
#define SSR_ORE          0x08U
#define SSR_FRE          0x10U
#define SSR_PE           0x20U
#define SSR_REC          0x80U

#define ESCR_P           0x08U
#define ESCR_PEN         0x10U
#define ESCR_INV         0x20U
#define ESCR_ESBL        0x40U
#define ESCR_FLWEN       0x80U
#define ESCR_DATABITS_8  0x00U
#define ESCR_DATABITS_5  0x01U
#define ESCR_DATABITS_6  0x02U
#define ESCR_DATABITS_7  0x03U
#define ESCR_DATABITS_9  0x04U

#define BGR_EXT          0x8000U

#define FCR1_FSEL        0x01U
#define FCR1_FTIE        0x02U
#define FCR1_FDRQ        0x04U
#define FCR1_FRIIE       0x08U
#define FCR1_FLSTE       0x10U

#define FCR0_FE1         0x01U
#define FCR0_FE2         0x02U
#define FCR0_FCL1        0x04U
#define FCR0_FCL2        0x08U
#define FCR0_FSET        0x10U
#define FCR0_FLD         0x20U
#define FCR0_FLST        0x40U

typedef struct {
    union {
        FM3_MFS03_UART_TypeDef uart03;
        FM3_MFS47_UART_TypeDef uart47;
    };
} FM3_MFS_UART_TypeDef;

typedef void (MFSTX_IRQHandler)(void *param);
typedef void (MFSRX_IRQHandler)(void *param);

void MFS0RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS1RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS2RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS3RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS4RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS5RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS6RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS7RX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS0TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS1TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS2TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS3TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS4TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS5TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS6TX_IRQHandler(void *param) __attribute__ ((interrupt));
void MFS7TX_IRQHandler(void *param) __attribute__ ((interrupt));

#endif /* FM3_USART_H_ */
